<%@ page import="com.cysyz.web.modules.base.permission.support.PrivilegeType" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>权限配置</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <%--<link rel="stylesheet" href="/js/compont/zTree_v3/css/demo.css" type="text/css">--%>
    <link rel="stylesheet" type="text/css" media="screen" href="/css/base/common.css" title="Version 1">
    <link href="/css/page/front/org_styles.css" rel="stylesheet" type="text/css" />
    <link href="/css/base/reset.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/css/base/table_org.css"/>

    <link rel="stylesheet" href="/js/compont/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/js/base/jquery.min.js"></script>
    <script type="text/javascript" src="/js/compont/jquery/jquery.mytab.js"></script>
    <script type="text/javascript" src="/js/compont/zTree_v3/js/jquery.ztree.core-3.5.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#tab-container").mytab({
                skinName: "ui-tab-simple"
            });

            $(document).bind("keydown",function(e){
                //alert(e.keyCode);
                e=window.event||e;
                if(e.keyCode==116){
                    e.keyCode = 0;
                    main_content.window.location.reload(); //屏蔽F5刷新键
                    return false; //屏蔽F5刷新键
                }
            });

            $("[privilegeCheckBox=privilegeGroupGroup]").click(function () {
                var status = false;
                if ($(this).attr("checked")) {
                    status = true;
                }
                var selector = "[privilegeGroupGroup=" + $(this).attr("value") + "]:checkbox";
                //alert(selector)
                $(selector).attr("checked", status)
            });

            $("[privilegeCheckBox=privilegeGroup]").click(function () {
                var status = false;
                if ($(this).attr("checked")) {
                    status = true;
                }
                var selector = "[privilegeGroup=" + $(this).attr("value") + "]:checkbox";
                //alert(selector)
                $(selector).attr("checked", status);


                var privilegeGroupGroupCheck =false;
                $("[privilegeCheckBox=privilegeGroup][privilegeGroupGroup="+$(this).attr("privilegeGroupGroup")+"]").each(function () {
                    if ($(this).attr("checked")) {
                        privilegeGroupGroupCheck = true;
                        return false;
                    }
                });
                $("[value=" + $(this).attr("privilegeGroupGroup") + "]:checkbox").attr("checked", privilegeGroupGroupCheck);

            });


            $("[privilegeCheckBox=privilege]").click(function () {
                var status = false;
                if ($(this).attr("checked")) {
                    status = true;
                }

                if ($(this).attr("menuPrivilegeId") != "") {
                    var selector = "[value=" + $(this).attr("menuPrivilegeId") + "]:checkbox";
                    //alert(selector)
                    $(selector).attr("checked", status);
                }

                var privilegeGroupCheck =false;
                $("[privilegeCheckBox=privilege][privilegeGroup="+$(this).attr("privilegeGroup")+"]").each(function () {
                    if ($(this).attr("checked")) {
                        privilegeGroupCheck = true;
                        return false;
                    }
                });

                var selector = "[value=" + $(this).attr("privilegeGroup") + "]:checkbox";
                //alert(selector)
                $(selector).attr("checked", privilegeGroupCheck);

                var privilegeGroupGroupCheck =false;
                $("[privilegeCheckBox=privilege][privilegeGroupGroup="+$(this).attr("privilegeGroupGroup")+"]").each(function () {
                    if ($(this).attr("checked")) {
                        privilegeGroupGroupCheck = true;
                        return false;
                    }
                });
                $("[value=" + $(this).attr("privilegeGroupGroup") + "]:checkbox").attr("checked", privilegeGroupGroupCheck);
            });



        });
    </script>

</head>
<body>
<div class="row col-sm-offset-2" style="margin-bottom: 10px; height:767px">
    <form action="${controllerUrlPrefix}/setPrivilege.do" class="form-horizontal">
        <input type="hidden" name="roleId" value="${roleId}"/>
        <div id="tab-container">
            <%--tab--%>
            <div id="row" >
                <div id="tabNavDiv" class="col-sm-8 col-sm-offset-1">
                    <ul>
                        <c:set var="menuGroupGroupType" value="<%=PrivilegeType.PRIVILEGE_GROUP_GROUP%>" />
                        <c:forEach var="privilegeGroupGroup" items="${allPrivilege}">
                            <c:if test="${privilegeGroupGroup.type == menuGroupGroupType && privilegeGroupGroup.childPrivilegeDto != null && !empty privilegeGroupGroup.childPrivilegeDto}">
                                <li targetDivId="${privilegeGroupGroup.id}">
                                    <input type="checkbox" value="${privilegeGroupGroup.id}" name="privilegeIds" privilegeCheckBox="privilegeGroupGroup" style="vertical-align: middle"
                                            <c:if test="${privilegeGroupGroup.roleHasThisPrivilege}">
                                                checked="checked"
                                            </c:if>
                                            />
                                    <a style="float: right;vertical-align: middle; padding: 5px 15px 5px 3px;">${privilegeGroupGroup.name}</a>
                                </li>

                            </c:if>

                        </c:forEach>
                    </ul>
                </div>
            </div>

            <div style="clear: both; margin-bottom: 20px"></div>

            <c:set var="menuType" value="<%=PrivilegeType.MENU%>" />
            <%--tab页--%>
            <c:forEach var="privilegeGroupGroup" items="${allPrivilege}">
                <div class="col-sm-9" id="${privilegeGroupGroup.id}">
                    <c:forEach var="privilegeGroup" items="${privilegeGroupGroup.childPrivilegeDto}" varStatus="status">
                        <dl  class="pull-left col-sm-3">
                            <dt>
                                <input type="checkbox" value="${privilegeGroup.id}" name="privilegeIds" privilegeGroupGroup="${privilegeGroupGroup.id}" privilegeCheckBox="privilegeGroup"
                                        <c:if test="${privilegeGroup.roleHasThisPrivilege}">
                                            checked="checked"
                                        </c:if>
                                        />
                                <c:set var="privilegeGroupType" value="<%=PrivilegeType.PRIVILEGE_GROUP%>" />
                                <span style="
                                <c:if test="${privilegeGroup.type == privilegeGroupType}">
                                        color:#0099ff;
                                </c:if>

                                        ">${privilegeGroup.name}</span>
                            </dt>
                            <c:forEach var="privilege" items="${privilegeGroup.childPrivilegeDto}">
                                <dd style="
                                <c:if test="${privilege.type == menuType}">
                                        display:none;
                                </c:if>
                                        ">
                                    <input type="checkbox" value="${privilege.id}" name="privilegeIds" privilegeGroupGroup="${privilegeGroupGroup.id}" privilegeGroup="${privilegeGroup.id}" privilegeCheckBox="privilege"
                                           menuPrivilegeId="${privilege.menuPrivilege.id}"
                                            <c:if test="${privilege.roleHasThisPrivilege}">
                                                checked="checked"
                                            </c:if>
                                            />


                                    <span style="


                                    ">${privilege.name}</span>
                                </dd>
                            </c:forEach>
                        </dl>
                        <c:if test="${status.index % 3 == 0 and status.index != 0}">
                            <div style="clear: both; margin-bottom: 10px"></div>

                        </c:if>
                        <%--<br/>--%>
                    </c:forEach>
                </div>
            </c:forEach>
        </div>
        <div style="clear: both; margin-bottom: 15px"></div>

        <div class="col-sm-offset-1 col-sm-8" >
            <input type="submit" value="保存" class="btn btn-primary btn-sm"/>
        </div>
    </form>

</div>

</body>
</html>
